###docker version:1.12.6
setenforce 0
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
systemctl stop firewalld
systemctl disable firewalld

echo "设置docker安装源和依赖包安装"
yum clean all
yum makecache
yum install -y ebtables wget  yum-utils device-mapper-persistent-data lvm2 ntpdate 
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
yum-config-manager --enable docker-ce-edge

#  yum install docker-ce -y
echo "设置系统时区"
##调整系统TimeZone
timedatectl set-timezone Asia/Shanghai

##将当前的UTC时间写入硬件时钟
timedatectl set-local-rtc 0

##重启依赖于系统时间的服务
systemctl restart rsyslog
systemctl restart crond
#systemctl enable ntpdate.service

echo '*/30 * * * * /usr/sbin/ntpdate ntp1.aliyun.com >/dev/null 2>&1' > /tmp/crontab2.tmp
crontab /tmp/crontab2.tmp
#systemctl start ntpdate.service

echo "* soft nofile 65535" >> /etc/security/limits.conf
echo "* hard nofile 65535" >> /etc/security/limits.conf
echo "* soft nproc 65535"  >> /etc/security/limits.conf
echo "* hard nproc 65535"  >> /etc/security/limits.conf
#echo "* soft  memlock  unlimited"  >> /etc/security/limits.conf
#echo "* hard memlock  unlimited"  >> /etc/security/limits.conf

#开启IPV4转发
echo 1 > /proc/sys/net/ipv4/ip_forward
echo "net.ipv4.ip_forward = 1" >> /etc/sysctl.conf
true /etc/sysctl.conf
/sbin/sysctl -p


#查看docker版本
#yum list docker-engine showduplicates
echo "安装docker"
#yum install -y docker-ce
yum localinstall -y docker-engine-*
echo "Docker installed successfully!"

#docker存储目录
if [ ! -n "$DOCKER_GRAPH" ]; then
    export DOCKER_GRAPH="/dodata/docker"
fi

#docker加速器
if [ ! -n "$DOCKER_MIRRORS" ]; then
    export DOCKER_MIRRORS="https://74b3ktvp.mirror.aliyuncs.com"
fi

# 如果/data/docker目录不存在，就创建目录
if [ ! -d "/etc/docker" ]; then
     mkdir -p /etc/docker
fi

# 配置加速器
cat > /etc/docker/daemon.json <<EOF
{
    "registry-mirrors": [ "${DOCKER_MIRRORS}" ],
    "graph": "${DOCKER_GRAPH}",
    "storage-driver": "overlay",
    "log-driver": "json-file",
    "log-opts": { "max-size":"100m","max-file":"2" }
}
EOF
echo "Config docker success!"

sed -i '/ExecStart/ s/$/\ \$DOCKER_NETWORK_OPTIONS/' /usr/lib/systemd/system/docker.service

systemctl daemon-reload
systemctl enable docker
systemctl start docker
echo "Docker start successfully!"

